package com.film.controller;

import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.domain.Film;
import com.film.domain.FilmType;
import com.film.service.FilmService;
import com.film.service.FilmTypeService;
import com.film.service.impl.FilmServiceImpl;
import com.film.service.impl.FilmTypeServiceImpl;
/**
 * 该控制类用来做热门电影
 * @author 2119196781
 *
 */
@WebServlet("/hotFilm.do")
public class HotFilmController extends HttpServlet{
	private FilmService filmService = new FilmServiceImpl();
	private FilmTypeService filmTypeService = new FilmTypeServiceImpl();
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		Set<String> filmShowTimeSet = new LinkedHashSet<>();
		
		HttpSession session = request.getSession();
		List<FilmType> types = filmTypeService.selectAllFilmType();
		//查询全部电影
		List<Film> allFilmList = filmService.selectAllFilm();
		//查询所有电影产地
		Set<String > placeSet = new HashSet<>();
		List<String> places = filmService.selectFilmPlace();
		for(String place:places) {
			String[] strs = place.split(",");
			for(String str:strs) {
				placeSet.add(str);
			}
		}
		//查询所有电影的上映时间
		List<String> filmShowTimes = filmService.selectFilmShowTime();
		for(String s:filmShowTimes) {
			filmShowTimeSet.add(s.substring(0,4));
		}
	
	
		session.setAttribute("filmShowTimes", filmShowTimeSet);
		session.setAttribute("types", types);
		session.setAttribute("places", placeSet);
		//热门电影
		List<Film> hotFilm = filmService.selectHotFilm();
		session.setAttribute("films", hotFilm);	
		session.setAttribute("film", hotFilm);	
		session.setAttribute("allFilmList", allFilmList);
		session.setAttribute("filmSize", hotFilm.size());
		response.sendRedirect("showFilm.jsp?flage=0&flag1=-1&flag2=-1&flag3=-1&flag4=-1&flag=1");
	}
}
